package cn.lwy.example.niit_race.controller;

import cn.lwy.example.niit_race.pojo.SysUser;
import cn.lwy.example.niit_race.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class LoginController {
    @Autowired
    LoginService loginService;

    @RequestMapping({"/","/index"})
    public String index(){
        return "index";
    }

    @RequestMapping("/toLogin")
    public String login(){
        return "login";
    }

    @RequestMapping("/toRegister")
    public String toRegister(){
        return "register";
    }
    @RequestMapping("/register")
    public String register(SysUser user){
        user.setRoleId(1);
        loginService.addUser(user);
        return "redirect:/toLogin";
    }
}
